package operator.combine;

import io.reactivex.Observable;
import io.reactivex.functions.Consumer;
import util.Printer;
import util.RxJavaHelper;

class ConcatOperator {

    public static void main(String[] args) {
//        concat();
//        concatArray();
        concatArrayDelayError();
    }

    /***
     * 不同数据源汇总，最多4个
     */
    static void concat() {
        Observable.concat(Observable.just(1, 2)
                , Observable.just(3, 4)
                , Observable.just(5, 6)
                , Observable.just(7, 8))
                .subscribe(new Consumer<Integer>() {
                    @Override
                    public void accept(Integer integer) throws Exception {
                        Printer.print(integer);
                    }
                });
    }


    /***
     * 不同数据源汇总，不限数量
     */
    static void concatArray() {
        Observable.concatArray(Observable.just(1, 2)
                , Observable.just(3, 4)
                , Observable.just(5, 6)
                , Observable.just(7, 8))
                .subscribe(new Consumer<Integer>() {
                    @Override
                    public void accept(Integer integer) throws Exception {
                        Printer.print(integer);
                    }
                });
    }


    static void concatArrayDelayError(){
        Observable.concatArrayDelayError(RxJavaHelper.getErrorObservable(), Observable.just("123"))
                .subscribe(new Consumer<String>() {
                    @Override
                    public void accept(String s) throws Exception {
                        Printer.print("concatArrayDelayError s = " + s);
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        Printer.print("concatArrayDelayError throwable = " + throwable);
                    }
                });
    }




}
